<?php
/**
 * CustomerController
 *
 * @author
 * @version
 */
class Admin_CustomerController extends AdminBaseController
{
	private $db_users;
	
	public function init()
	{
		parent::init();
		
		$this->db_users = new Users();
	}
	
	/**
	 * The default action - show the home page
	 */
	public function indexAction ()
	{
		$grid = new Zend_Config_Xml(BP . '/config/grid/customer.xml');
		
		$select = $this->db_users->getSelect();
		$users = $this->db_users->getUsers();
		
		$paginator = Zend_Paginator::factory($select);
		$paginator->setItemCountPerPage($grid->default->itemCountPerPage);
		$paginator->setCurrentPageNumber($grid->default->currentPageNumber);

		$this->view->paginator = $paginator;
		
		
		
//		Zend_debug::dump('总页数:' . $paginator->count());
//		Zend_debug::dump('当前页:' . $paginator->getCurrentPageNumber());
//		Zend_debug::dump('每页数量:' . $paginator->getItemCountPerPage());
//		Zend_debug::dump($paginator->getCurrentItems());
		
		$this->view->id = $grid->id;
		$this->view->pagerVisibility = $grid->pagerVisibility;
		$this->view->exportTypes = $grid->exportTypes;
		$this->view->actionItems = $grid->actionItems;
		
	}
	
	public function getusersAction()
	{
		$start = $this->_request->getParam('start');
		$count = $this->_request->getParam('limit');
		$page = $start / $count;
		
		$sort = $this->_request->getParam('sort') ? $this->_request->getParam('sort') : NULL;
		$dir = $this->_request->getParam('dir') ? $this->_request->getParam('dir') : NULL;
		
		$order = ($sort != NULL && $dir != NULL)? $sort . ' ' . $dir : NULL;
		
		$usersArray['totalCount'] = $this->db_users->getUsersTotalCount();
		if ($order)
		{
			$usersArray['users'] = $this->db_users->getUsers($page+1, $count, $order);
		}else {
			$usersArray['users'] = $this->db_users->getUsers($page+1, $count);
		}
		
		echo(Zend_Json::encode($usersArray));

		//$log = Zend_Registry::get('log');
		//$log->info(Zend_debug::dump($this->_request->getParams()));
	}
	

}
?>